#include <iostream>
#include <fcntl.h>
#include <unistd.h>

using namespace std;

const char* dev_path = "/dev/registerchrdev";

int main(int argc, char** argv)
{
    int fd = open(dev_path, O_RDWR);
    if (fd < 0) {
        cout << "open char device failed, fd = " << fd << endl;
        cout << "please check if the device is exist, path = " << dev_path << endl;
        cout << "please check the permission of the device, path = " << dev_path << endl;
        return -1;
    }
    else
    {
        cout << "open char device success, fd = " << fd << endl;
    }

    // char buf[128] = {0};
    // int ret = read(fd, buf, sizeof(buf));
    // if (ret < 0) {
    //     cout << "read misc device failed, ret = " << ret << endl;
    //     return -1;
    // }

    // cout << "success to read " << ret << " bytes from misc device: " << buf << endl;

    // ret = write(fd, "hello misc device", 17);
    // if (ret < 0) {
    //     cout << "write misc device failed, ret = " << ret << endl;
    //     return -1;
    // }

    // cout << "success to write " << ret << " bytes to misc device" << endl;

    // // read again
    // ret = read(fd, buf, sizeof(buf));
    // if (ret < 0) {
    //     cout << "read misc device failed, ret = " << ret << endl;
    //     return -1;
    // }

    // cout << "success to read " << ret << " bytes from misc device: " << buf << endl;

    close(fd);
    return 0;
}
